﻿using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RayDen.RayEngine.Core.Interface;

namespace RayDen.RayEngine.Core.Types
{
    public class InputRayBufferCollection<TRayBuffer>
        where TRayBuffer : IRayBufferBase
    {
        private readonly ConcurrentBag<Tuple<int, TRayBuffer>> queue;
        private readonly BlockingCollection<Tuple<int, TRayBuffer>> collection;
        public InputRayBufferCollection()
        {
            queue = new ConcurrentBag<Tuple<int, TRayBuffer>>();
            collection = new BlockingCollection<Tuple<int, TRayBuffer>>(queue);
        }

        public Tuple<int, TRayBuffer> Get()
        {
            return collection.Take();
            /*
            Tuple<int, RayBuffer> rb;
            while(queue.IsEmpty) {}
            queue.TryDequeue(out rb);
            return rb;
             */
        }

        public void Put(Tuple<int, TRayBuffer> tuple)
        {
            collection.Add(tuple);
        }
    }

    public class InputRayBufferCollection : InputRayBufferCollection<RayBuffer>
    {
    }
}
